package org.ymf.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.beans.BeanUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.layuiframework.stereotype.elasticsearch.ElasticsearchRecord;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 用户
 * </p>
 *
 * @author Malphite
 * @since 2023-08-03
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="User对象", description="用户")
public class User extends ElasticsearchRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @ExcelProperty(value = "id")
    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ExcelProperty(value = "账号")
    @ApiModelProperty(value = "账号")
    @TableField("userAccount")
    private String useraccount;

    @ExcelProperty(value = "密码")
    @ApiModelProperty(value = "密码")
    @TableField("userPassword")
    private String userpassword;

    @ExcelProperty(value = "用户昵称")
    @ApiModelProperty(value = "用户昵称")
    @TableField("userName")
    private String username;

    @ExcelProperty(value = "用户头像")
    @ApiModelProperty(value = "用户头像")
    @TableField("userAvatar")
    private String useravatar;

    @ExcelProperty(value = "用户角色：user/admin")
    @ApiModelProperty(value = "用户角色：user/admin")
    @TableField("userRole")
    private String userrole;

    @ExcelProperty(value = "创建时间")
    @ApiModelProperty(value = "创建时间")
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createtime;

    @ExcelProperty(value = "更新时间")
    @ApiModelProperty(value = "更新时间")
    @TableField(value = "updateTime", fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date updatetime;

    @ExcelProperty(value = "是否删除")
    @ApiModelProperty(value = "是否删除")
    @TableField("isDelete")
    @TableLogic
    private Integer isdelete;


    /**
     * 将{@linkplain User 数据库映射对象} 转化为 {@linkplain UserEs Elasticsearch映射对象}
     */
    public UserEs transform(){
        UserEs entity = new UserEs();
        BeanUtils.copyProperties(this, entity);
        return entity;
    }
}
